package com.mzy.linear_struct.hot100.哈希表;



import java.util.*;

/**
 * @Author: mizy3
 * @Date: 2024/08/08/下午10:38
 * @Description:
 */
public class Pro49字母异位词分组 {

    public List<List<String>> groupAnagrams(String[] strs) {
        HashMap<String, List<String>> map = new HashMap<>();
        for (String str : strs) {
            char[] s = str.toCharArray();
            Arrays.sort(s);
            map.computeIfAbsent(new String(s), key -> new ArrayList<>()).add(str);
        }


        return new ArrayList<>(map.values());
    }

    public static void main(String[] args) {
        String[] strs = {"eat", "tea", "tan", "ate", "nat", "bat"};
        System.out.println(new Pro49字母异位词分组().groupAnagrams(strs));
    }

}



















